package edu.usx.server.mapper;

import edu.usx.server.pojo.Msg;
import edu.usx.server.pojo.MsgContent;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface MsgMapper {
    @Select("select sys_msg_content.id,title,message,createDate from sys_msg_content join sys_msg on sys_msg_content.id = sys_msg.mid where userid=#{userId}")
    List<MsgContent> findMsgByUserId(Integer userId);
    //一键已读
    @Update("update sys_msg set state='1' where userid=#{userId}")
    void updateAllMsgState(Integer userId);

    @Update("update sys_msg set state='1' where userid=#{userId} and mid=#{msgId}")
    void updateMsgState(Integer userId, Integer msgId);

    @Select("select state from sys_msg where userid=#{userId} and mid=#{msgId}")
    Msg findMsgStateByUserIdAndMsgId(Integer userId, Integer msgId);

    @Select("select count(*) from sys_msg where state='0' and userid=#{userId}")
    Integer findUnReadMsgCountByUserId(Integer userId);
}
